perm filename EEXPED.2[EAL,HE]2 blob
sn#701194 filedate 1983-03-23 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00004 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Editor: Expression editor and related routines }
C00024 00003 { Externally defined routines from elsewhere: }
C00026 00004 (* expression/line editor: exprEditor *)
C00041 ENDMK
C⊗;
{$NOMAIN Editor: Expression editor and related routines }
const
(* Constants from EDIT *)
maxLines = 28; (* smaller on the 11 than on the 10 *)
maxPPLines = 18;
maxBpts = 25;
maxTBpts = 20; (* max could be exceeded by huge case stmnt *)
listinglength = 2000; (* Length of Listingarray *)
(* Random type declarations for OMSI/SAIL compatibility *)
type
byte = 0..255; (* doesn't really belong here, but... *)
ascii = char;
atext = text;
{ Define all the pointer types here }
strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
pdbp = ↑pdb;
envheaderp = ↑envheader;
enventryp = ↑enventry;
environp = ↑environment;
cmoncbp = ↑cmoncb;
linerecp = ↑linerec;
cursorpp = ↑cursorp; {Ron's style, not mine}
(* This one is used whenever a pointer is needed for which the *)
(* definition is missing from this file; naturally, all *)
(* pointers use the same space *)
dump = ↑integer;
(* datatype definitions *)
datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
frametype, eventtype, strngtype, labeltype, proctype, arraytype,
reftype, valtype, cmontype, nulltype, undeftype,
dimensiontype, mactype, macargtype, freevartype);
scalar = real;
cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;
strng = record
next: strngp;
ch: cstring;
end;
(* statement definitions *)
stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
fortype, iftype, whiletype, untiltype, casetype,
calltype, returntype,
printtype, prompttype, pausetype, aborttype, assigntype,
signaltype, waittype, enabletype, disabletype, cmtype,
affixtype, unfixtype,
movetype, operatetype, opentype, closetype, centertype,
stoptype, retrytype,
requiretype, definetype, macrotype, commenttype, dimdeftype,
setbasetype, wristtype, tovaltype, declaretype, emptytype);
(* more??? *)
statement = packed record
next, last: statementp; (* ↑ to lexical tokens? *)
stlab: varidefp;
exprs: nodep; (* any expressions used by this statement *)
nlines: integer;
bpt: boolean;
case stype: stmntypes of
progtype: (pcode: statementp; errors: integer);
blocktype,
declaretype,
endtype,
coendtype: (bcode, bparent: statementp; blkid: identp;
level, numvars: 0..255; variables: varidefp);
coblocktype: (threads: nodep; nthreads: integer; cblkid: identp);
fortype: (forvar, initial, step, final: nodep; fbody: statementp);
casetype: (index: nodep; range, ncases: integer; caselist: nodep);
untiltype: (cond: nodep; body: statementp);
iftype: (icond: nodep; thn, els: statementp);
aborttype: (plist: nodep; debugLev: integer);
cmtype: (oncond: nodep; conclusion: statementp;
deferCm, exprCm: boolean; cdef: varidefp);
end;
(* auxiliary definitions: variable, etc. *)
varidef = packed record
next,dnext: varidefp;
name: identp;
level: 0..255; (* environment level *)
offset: 0..255; (* environment offset *)
dtype: varidefp; (* to hold the dimension info *)
tbits: 0..15; (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
dbits: 0..15; (* for use by debugger/interpreter *)
case vtype: datatypes of
arraytype: (a: nodep);
proctype: (p: nodep);
labeltype,
cmontype: (s: statementp);
mactype: (mdef: statementp);
macargtype: (marg: tokenp);
pconstype: (c: nodep);
dimensiontype: (dim: nodep);
end;
(* definition of the ubiquitous NODE record *)
nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
deprnode, viaptnode, apprnode, destnode, durnode,
sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
arrivalnode, departingnode,
ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
calcnode, arraydefnode, bnddefnode, bndvalnode,
waitlistnode, procdefnode, tlistnode, dimnode, commentnode);
exprtypes = ( svalop, (* scalar operators *)
sltop, sleop, seqop, sgeop, sgtop, sneop, (* relations *)
notop, orop, xorop, andop, eqvop, (* logical *)
saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
sexpop, maxop, minop, intop, idivop, modop,
sqrtop, logop, expop, timeop, (* functions *)
sinop, cosop, tanop, asinop, acosop, atan2op, (* trig *)
vdotop, vmagnop, tmagnop,
vecop, (* vector operators *)
vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
svmulop, vsmulop, vsdivop, tvmulop, wrtop,
tposop, taxisop,
transop, (* trans operators *)
tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
ioop, (* i/o operators *)
queryop, inscalarop,
specop, (* special operators *)
arefop, callop, grinchop, macroop, vmop, adcop, dacop,
badop,
addop, subop, negop, mulop, divop, absop); (* for parsing *)
leaftypes = pconstype..strngtype;
reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);
node = record
next: nodep;
case ntype: nodetypes of
exprnode: (op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
leafnode: (case ltype: leaftypes of
varitype: (vari: varidefp; vid: identp);
pconstype: (cname: varidefp; pcval: nodep);
svaltype: (s: scalar; wid: integer);
vectype: (v: dump);
transtype: (t: dump);
strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
listnode: (lval: nodep);
clistnode: (cval: integer; stmnt: statementp; clast: nodep);
colistnode: (prev: nodep; cstmnt: statementp);
errornode: (eexpr: nodep);
calcnode: (rigid, frame1: boolean; other: dump; case tvarp: boolean of
false: (tval: dump); true: (tvar: enventryp) );
arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
bnddefnode: (lower, upper: nodep);
bndvalnode: (lb, ub, mult: integer);
waitlistnode: (who: pdbp; when: integer);
procdefnode:(ptype: datatypes; level: 0..255;
pname, paramlist: varidefp; body: statementp);
tlistnode: (tok: tokenp);
dimnode: (time, distance, angle, dforce: integer);
end;
(* records for parser: ident, token, resword *)
ident = record
next: identp;
length: integer;
name: strngp;
predefined: varidefp;
end;
tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
macpartype);
constypes = svaltype..strngtype;
reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);
filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
sourcefiletype,steptype,thentype,totype,untltype,viatype,
withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
ontype,offtype,ppsizetype,collecttype,alltype,lextype);
clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
errortype,forcetype,forceframetype,forcewristtype,gathertype,
nildeproachtype,nonullingtype,nullingtype,stiffnesstype,
torquetype,velocitytype,wobbletype,
cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
fxtype,fytype,fztype,mxtype,mytype,mztype,
t1type,t2type,t3type,t4type,t5type,t6type,tbltype);
edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
popcmd);
token = record
next: tokenp;
case ttype: tokentypes of
constype: (cons: nodep);
comnttype: (len: integer; str: strngp);
delimtype: (ch: ascii);
reswdtype: (case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes) );
identtype: (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
end;
resword = record
next: reswordp;
length: integer;
name: strngp;
case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes);
end;
(* process descriptor blocks & environment record definitions *)
queuetypes = (nullqueue,nowrunning,runqueue,inputqueue,eventqueue,sleepqueue,
forcewait,devicewait,joinwait,proccall);
pdb = packed record
nextpdb,next: pdbp; (* for list of all/active pdb's *)
level: 0..255; (* lexical level *)
mode: 0..255; (* expression/statement/sub-statement *)
priority: 0..255;
status: queuetypes; (* what are we doing *)
env: envheaderp;
spc: statementp; (* current statement *)
epc: nodep; (* current expression (if any) *)
sp: nodep; (* intermediate value stack *)
cm: cmoncbp; (* if we're a cmon point to our definition *)
mech: dump; (* current device being used *)
linenum: integer; (* used by editor/debugger *)
case procp: boolean of (* true if we're a procedure *)
true: (opdb: pdbp; (* pdb to restore when procedure exits *)
pdef: nodep); (* procedure definition node *)
false: (evt: dump; (* event to signal when process goes away *)
sdef: statementp); (* first statement where process was defined *)
end;
envheader = packed record
parent: envheaderp;
env: array [0..4] of environp;
varcnt: 0..255; (* # of variables in use ??? *)
case procp: boolean of (* true if we're a procedure *)
true: (proc: nodep);
false:(block: statementp);
end;
enventry = record
case etype: datatypes of
svaltype: (s: scalar);
vectype: (v: dump);
transtype: (t: dump);
frametype: (f: dump);
eventtype: (evt: dump);
strngtype: (length: integer; str: strngp);
cmontype: (c: cmoncbp);
proctype: (p: nodep; penv: envheaderp);
reftype: (r: enventryp);
arraytype: (a: envheaderp; bnds: nodep);
end;
environment = record
next: environp;
vals: array [0..9] of enventryp;
end;
cmoncb = record
running, enabled: boolean; (* cmon's status *)
cmon: statementp;
pdb: pdbp;
evt: dump;
fbits: integer; (* bits for force sensing *)
oldcmon: cmoncbp; (* for debugger *)
end;
(* print related records: *)
cursorp = record
cline,ind: integer;
case stmntp: boolean of
true: (st: statementp);
false: (nd: nodep);
end;
linerec = record
next: linerecp;
start,length: integer
end;
listingarray = packed array [0..listinglength] of ascii;
(* Global variables *)
var
(* From ALMAIN *)
b:boolean;
ch:ascii;
ltime: real;
(* From PARSE *)
reswords: array [0..26] of reswordp;
idents: array [0..26] of identp;
macrostack: array [1..10] of tokenp;
curmacstack: array [1..10] of varidefp;
macrodepth: integer;
curchar, maxchar, curline: integer;
curBlock,newDeclarations: statementp;
curProc: varidefp;
pnode: nodep;
nodim, distancedim, timedim, angledim,
forcedim, torquedim, veldim, angveldim: varidefp;
fvstiffdim, mvstiffdim: nodep;
(* filedepth: integer;
curpage: integer;
sysVars,unVars: varidefp;
errcount: integer;
outerBlock: statementp;
curVariable: varidefp;
curMotion: statementp;
endOk,coendOk: integer;
moveLevel: integer;
curErrhandler, curCmon: statementp; *)
d1: array[1..13] of dump;
endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
(* semiseen, shownline: boolean;
eofError: boolean;
inMove,inCoblock: boolean; *)
d2,d3,d4,d5,d6: boolean;
curtoken: token;
file1,file2,file3,file4,file5: atext;
line: linestr;
(* From INTERP *)
curInt, activeInts, readQueue, allPdbs: pdbp;
(* curEnv, sysEnv: envheaderp;
clkQueue: nodep;
allEvents: dump;
STLevel: integer;
etime: integer;
curtime: integer;
stime: integer;
msg: dump;
inputp: integer; *)
d10: array[1..10] of integer;
debugLevel: integer;
tSingleThreadMode: boolean;
resched, running, escapeI, singleThreadMode: boolean;
msgp: boolean; (* flag set if any messages pending *)
inputReady: boolean;
inputLine: array [1..20] of ascii;
(* From EDIT *)
lines: array [1..maxLines] of linerecp;
ppLines: array [1..maxPPLines] of linerecp;
marks: array [1..20] of integer;
cursorStack: array [1..15] of cursorp;
bpts: array [1..maxBpts] of statementp;
tbpts: array [1..maxTBpts] of statementp;
debugPdbs: array [0..10] of pdbp;
screenheight,dispHeight: integer;
ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
firstDline,topDline,botDline,firstLine,lastLine: integer;
freeLines,oldLines: linerecp;
findStmnt: statementp;
nbpts,ntbpts: integer;
eCurInt: pdbp;
dProg: statementp;
smartTerminal: boolean;
setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
backUp: boolean;
eSingleThreadMode: boolean;
listing: listingarray;
lbuf: array [1..160] of ascii;
ppBuf: array [1..100] of ascii;
outFile: atext;
curToken: token;
(* Various device & variable pointers *)
speedfactor: enventryp;
barm: dump;
(* Various constant pointers *)
xhat,yhat,zhat,nilvect: dump;
niltrans: dump;
bpark, ypark, gpark, rpark: dump; (* arm park positions *)
{ Externally defined routines from elsewhere: }
(* From EAUX1A *)
function getAChar: ascii; external;
procedure out1Line(line,start,length: integer); external;
procedure borderLines; external;
(* From PP *)
procedure ppLine; external;
(* From DISP *)
procedure beep; external;
procedure showCursor(line,col: integer); external;
procedure outLine(line,col,start,length: integer); external;
function getChar: ascii; external;
procedure outChar(line,col: integer; ch: ascii; bold: boolean); external;
procedure insChar(line,col: integer; ch: ascii); external;
procedure delChar(line,col: integer); external;
(* expression/line editor: exprEditor *)
function exprEditor(line,lstart,llength,estart: integer;
var elength: integer; off: integer): ascii; external;
function exprEditor;
var i,j,iCh,col,elenOld,arg: integer;
ch,sch: ascii;
b,done,insertmode,search,right,overflow: boolean;
function seek(ch: ascii): integer;
var i,j,colf: integer;
begin
seek := 0; (* assume we don't find it *)
if ch = chr(15B) then (* need to treat <cr> specially *)
if right then seek := estart + elength (* end of expression *)
else seek := estart-1 (* start of expression *)
else if right then (* see which way to seek *)
begin (* seeking for char to right *)
i := col + 1;
colf := estart + elength;
for j := 1 to arg do
begin
while (listing[i] <> ch) and (i < colf) do i := i + 1;
if i < colf then
if j < arg then i := i + 1 (* look for another *)
else seek := i; (* found it *)
end
end
else
begin (* seeking for char to left *)
i := col - 1;
for j := 1 to arg do
begin
while (listing[i] <> ch) and (estart <= i) do i := i - 1;
if estart <= i then
if j < arg then i := i - 1 (* look for another *)
else seek := i; (* found it *)
end
end
end;
procedure dchar;
var i,j: integer;
begin
for i := col + arg to llength do listing[i-arg] := listing[i];
for i := llength - arg + 1 to llength do listing[i] := ' ';
if not smartTerminal then
outLine(line,col,col,llength-col+1)
else
begin
for i := 1 to arg do delChar(line,col);
if (llength > 80) and (col <= 80) then (* deal with overflow line *)
begin
if col + arg > 81 then j := col else j := 81-arg;
for i := j to 80 do (* shift in chars from overflow line *)
outChar(line,i,listing[i],i<(estart+elength-arg));
if llength - arg >= 80 then
begin (* shift overflow line to left *)
for i := 1 to arg do delChar(line+1,1);
end
else outLine(line+1,1,81,1) (* clear overflowed line *)
end
end;
elength := elength - arg; (* update lengths *)
llength := llength - arg;
end;
begin
search := true;
right := true;
sch := chr(0); (* so ↑R does nothing til after a search/kill is done *)
if llength < estart + elength - 1 then (* consistency check *)
elength := llength - estart + 1;
elenOld := elength; (* remember initial expr length *)
for i := 1 to llength do listing[i] := listing[lstart+i-1]; (* load line *)
if llength > 80 then
begin
outLine(line+1,1,81,llength-80); (* show overflow *)
overflow := true;
end
else overflow := false;
if smartTerminal then
for i := estart to estart+elength-1 do
outChar(line,i,listing[i],true); (* print expression in bold *)
done := false;
insertmode := (elength = 0) or (off <> 0);
col := estart + off;
repeat
showCursor(line,col);
repeat ch := getChar until ch <> chr(12B); (* skip over any <lf>'s *)
iCh := ord(ch);
if (iCh = 34B) or (iCh = 33B) then (* ↑\ or ALT *)
begin (* get repeat count *)
arg := 0;
ch := getChar;
while ('0' <= ch) and (ch <= '9') do
begin
arg := 10*arg + (ord(ch) - ord('0')); (* get next digit *)
ch := getChar;
end;
iCh := ord(ch);
end
else arg := 1;
if (iCh <> 30B) and ((iCh < 37B) or (177B = iCh)) then (* control character *)
begin
if iCh = 177B then iCh := 10B; (* convert rubout to backspace *)
case iCh of
11B: insertmode := true; (* ↑I *)
10B: begin (* backspace *)
if col - arg < estart then arg := col - estart;
col := col - arg;
if insertmode and (arg > 0) then dchar;
end;
4B: begin (* ↑D *)
if col + arg > estart + elength then arg := estart + elength - col;
if arg > 0 then dchar;
end;
1B: col := col + arg; (* ↑A *)
5B: col := estart + elength; (* ↑E *)
6B: col := estart; (* ↑F *)
17B: begin (* ↑O *)
j := llength + elenOld - elength; (* restore initial line length *)
if j < llength then (* fix up end of line if needed *)
begin
for i := j to llength do listing[i] := ' ';
outLine(line,j,j,llength-j+1); (* clean up the display *)
end;
llength := j;
elength := elenOld; (* restore initial expr length *)
for i := estart to llength do listing[i] := listing[lstart+i-1]; (* reload it *)
if smartTerminal then (* redisplay line *)
begin
for i := estart to estart+elength-1 do
outChar(line,i,listing[i],true); (* print expression in bold *)
outLine(line,estart+elength,estart+elength,llength-estart-elength+1);
end
else outLine(line,estart,estart,llength-estart+1);
insertmode := false;
col := estart;
end;
32B: begin (* 32B is ↑Z *)
col := estart; (* zero the expression *)
arg := elength;
dchar;
elength := 0;
end;
22B: begin (* ↑R *)
i := seek(sch); (* repeat last search/kill command *)
if i > 0 then (* if we found another of the char *)
if search then col := i (* skip to it *)
else
if right then
begin
arg := i - col;
dchar; (* kill right to char *)
end
else
begin
if col = estart + elength then col := col - 1;
arg := col - i - 1;
col := i+1;
dchar; (* kill left to char *)
col := i;
end;
end;
23B: begin (* ↑S *)
search := true; (* remember for ↑R command *)
right := true;
sch := getAChar; (* skip right to char next typed *)
i := seek(sch);
if i > 0 then col := i; (* skip ahead if we found one *)
end;
2B: begin (* ↑B *)
search := true; (* remember for ↑R command *)
right := false;
sch := getAChar; (* skip left to char next typed *)
i := seek(sch);
if i > 0 then col := i; (* skip back if we found one *)
end;
24B: if col > estart + 1 then (* ↑T *)
begin
ch := listing[col-1]; (* transpose last two chars *)
listing[col-1] := listing[col-2];
listing[col-2] := ch;
if smartTermingl then
begin
outChar(line,col-2,ch,true); (* and update display *)
outChar(line,col-1,listing[col-1],true);
end
else outLine(line,col-2,col-2,llength-col+1);
end;
13B: begin (* ↑K <vt> *)
search := false; (* remember for ↑R command *)
right := true;
sch := getAChar; (* try to find char *)
i := seek(sch);
if i > 0 then
begin
arg := i - col;
dchar; (* kill right to char *)
end
end;
14B: begin (* ↑L <ff> *)
search := false; (* remember for ↑R command *)
right := false;
sch := getAChar; (* try to find char *)
i := seek(sch);
if i > 0 then
begin
(* if col = estart + elength then col := col - 1; *)
arg := col - i - 1;
col := i+1;
dchar; (* kill left to char *)
col := i;
end
end;
otherwise done := true;
end;
if (iCh <> 10B) and (iCh <> 11B) then insertmode := false;
end
else
begin (* ordinary character to insert *)
if insertmode then
begin
for j := llength downto col do listing[j+1] := listing[j];
listing[col] := ch; (* now insert the new character *)
elength := elength + 1; (* update lengths *)
llength := llength + 1;
if llength > 80 then
begin
if smartTerminal and not overflow then (* just overflowed *)
begin
listing[82] := ' ';
outLine(line+1,1,82,1); (* zero line *)
end;
overflow := true; (* indicate we've overflowed *)
end;
if llength > 140 then
begin (* No more room in line buffer!!! *)
beep;
if llength > 149 then
begin
llength := llength - 1;
elength := elength - 1;
if col = 150 then col := 149;
end;
end;
if smartTerminal then
begin
insChar(line,col,ch);
if (llength > 80) and (col <= 80) then
begin
insChar(line+1,1,listing[81]);
if estart+elength <= 81 then outChar(line+1,1,listing[81],false);
end;
end
else outLine(line,col,col,llength-col+1);
end
else
begin
listing[col] := ch; (* overwrite whatever was there *)
if smartTerminal then outChar(line,col,ch,true)
else outLine(line,col,col,llength-col+1);
end;
col := col + 1;
end;
if col < estart then col := estart; (* don't go before expression *)
if col >= estart + elength then (* at end of expression? *)
begin
col := estart + elength; (* don't let it get past either end *)
insertmode := true;
end;
until done;
if overflow then
begin (* restore clobbered line *)
if (line + 1 > dispHeight) or (line = dprog↑.nlines) then borderLines
else
with lines[firstDline+line]↑ do
out1Line(line+1,start,length);
end;
if llength < 150 then listing[llength+1] := ' '; (* for getToken *)
i := estart;
curChar := estart; (* set up for parsing the expression *)
maxChar := estart + elength - 1;
endOfLine := false;
backUp := false;
expandMacros := true;
iCh := ord(ch);
if iCh < 40B then
if iCh <> 15B then iCh := iCh + 100B; (* convert back to ascii *)
exprEditor := chr(iCh); (* activating character *)
end;